package com.schoolai.schoolstudy.controller;

import com.schoolai.entity.SchoolSetAfterSchoolService;
import com.schoolai.entity.SchoolStudyEnglishWorkTask;
import com.schoolai.schoolstudy.req.StudyEnglishWordTaskREQ;
import com.schoolai.schoolstudy.service.SchoolStudyEnglishWorkTaskService;
import com.schoolai.util.base.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author bobby
 * @since 2025-09-29
 */
@RestController
@RequestMapping("/SchoolStudyEnglishWorkTask")
@Tag(name = "任务记忆单词任务", description = "任务记忆单词任务")
public class SchoolStudyEnglishWorkTaskController {
    @Autowired
    private SchoolStudyEnglishWorkTaskService schoolStudyEnglishWorkTaskService;
    @Operation(summary = "查询任务记忆单词任务")
    @PostMapping("/search")
    @ApiResponses({
            @ApiResponse(responseCode = "20000", description = "操作成功"),
            @ApiResponse(responseCode = "999", description = "错误")
    })
    Result search(@RequestBody StudyEnglishWordTaskREQ req) {
        return Result.ok(schoolStudyEnglishWorkTaskService.queryPage(req));
    }

    /**
     * 通过记忆单词任务id查询单词列表
     * @param id
     * @return
     */
    @Operation(summary = "查询任务记忆单词任务")
    @GetMapping ("/{id}")
    public Result  getTaskAndListById(
            @Parameter(description = "任务ID", required = true, example = "1")
            @PathVariable("id") String id){
        return Result.ok(schoolStudyEnglishWorkTaskService.getTaskAndListById(id,true));
    }



    @Operation(summary = "新增记忆单词任务")
    @PostMapping
    public Result save(@RequestBody SchoolStudyEnglishWorkTask schoolStudyEnglishWorkTask){
        return Result.ok(schoolStudyEnglishWorkTaskService.saveOrUpdate(schoolStudyEnglishWorkTask));
    }
   @Operation(summary = "修改记忆单词任务信息")
    @PutMapping
    Result update(@RequestBody SchoolStudyEnglishWorkTask schoolStudyEnglishWorkTask){
        schoolStudyEnglishWorkTask.setUpdatedTime(new Date());
        return Result.ok(schoolStudyEnglishWorkTaskService.updateById(schoolStudyEnglishWorkTask));
    }
    @Operation(summary = "删除记忆单词任务信息")
    @DeleteMapping("/{id}")
    Result delete(@PathVariable("id") String id){
        return schoolStudyEnglishWorkTaskService.deleteTaskAndListById(id);
    }

}
